package rcs34.android.AndroidRC;

import java.io.File;
import java.io.IOException;

import org.json.JSONException;
import org.json.JSONObject;

public class FileInfo extends JSONObject {
  public String path;
  public FileInfo(File _file, String _root) {
    try {
      put("isDir", _file.isDirectory());
      if(_file.isFile()){
      put("size", _file.length());
      }else{
        String[] items=_file.list();
        int dirSize=0;
        if(items!=null){
          dirSize=items.length;
        }
        put("size",dirSize);
      }
      String aPath = _file.getAbsolutePath().substring(_root.length());
      if (aPath.length() < 1) {
        aPath = "/";
      }
      put("path", aPath);
      path=aPath;
    } catch (JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
}
